package com.hm.edu.fourcare;

import java.text.DateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.hm.edu.fourcare.models.PlannedMedikation;

public class Medikation extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_medikation);
		
		//Set Header Date
		DateFormat[] dateFormats = new DateFormat[] {
				  
				DateFormat.getDateInstance(),
				DateFormat.getDateTimeInstance(),	
		};
		
		java.text.DateFormat df = java.text.DateFormat.getDateTimeInstance();
		TextView headerDate = (TextView) findViewById(R.id.HeaderTextRight);
		headerDate.setText(dateFormats[0].format(new Date()).toString());
		
		//Init Medikamente
		PlannedMedikation pMedikation1 = new PlannedMedikation();
		pMedikation1.setMedikament("Carvedilol AAA Pharma");
		pMedikation1.setDosis("Dosis: 25mg");
		pMedikation1.setNextDate(new Date());
		
		PlannedMedikation pMedikation2 = new PlannedMedikation();
		pMedikation2.setMedikament("Insuman Rapid Pen");
		pMedikation2.setDosis("2 Einheiten");
		pMedikation2.setNextDate(new Date());
				
		//Set View Strings Med1
		TextView nameMed1 = (TextView) findViewById(R.id.NameMed1);
		nameMed1.setText(pMedikation1.getMedikament());
		
		TextView dosisMed1 = (TextView) findViewById(R.id.Med1LabelDosis);
		dosisMed1.setText(pMedikation1.getDosis());
		
		TextView datumMed1 = (TextView) findViewById(R.id.Med1LabelDatum);
		datumMed1.setText("letzte Verabreichung: " + dateFormats[1].format(pMedikation1.getNextDate()));
		
		//Set View Strings Med2
		TextView nameMed2 = (TextView) findViewById(R.id.NameMed2);
		nameMed2.setText(pMedikation2.getMedikament());
		
		TextView dosisMed2 = (TextView) findViewById(R.id.Med2LabelDosis);
		dosisMed2.setText("Dosis: " + pMedikation2.getDosis());
		
		TextView datumMed2 = (TextView) findViewById(R.id.Med2LabelDatum);
		datumMed2.setText("letzte Verabreichung: " + dateFormats[1].format(pMedikation2.getNextDate()));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.medikation, menu);
		return true;
	}
	
	public void submit(View view){
		
		Context context = getApplicationContext();
		CharSequence text = "Medikation gespeichert!";
		int duration = Toast.LENGTH_SHORT;

		Toast toast = Toast.makeText(context, text, duration);
		toast.show();
		
		Intent intent = new Intent(this, MainMenu.class);
		startActivity(intent);
	}
}
